import {
  getToken,
  setToken,
  getCityId,
  setCityId,
  getCityName,
  setCityName,
} from "@/utils/auth";
import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    parmas: {
      //筛选房屋参数
      cityId: getCityId() || "AREA|88cff55c-aaa4-e2e0",
      area: "",
      subway: "",
      rentType: true,
      start: 1,
      end: 10,
    },
    tokenLogin: getToken() || {},
    cityName: getCityName() || "北京",
  },
  mutations: {
    SET_TOKEN(state, payload) {
      state.tokenLogin = payload;
      setToken(payload);
    },
    SET_PARMAS_CITYID(state, payload) {
      state.parmas.cityId = payload;
      setCityId(payload);
    },
    SET_PARMAS_SUBWAY(state, payload) {
      state.parmas.subway = payload;
    },
    SET_PARMAS_AREA(state, payload) {
      state.parmas.area = payload;
    },
    SET_PARMAS_RENTTYPE(state, payload) {
      state.parmas.rentType = payload;
    },
    SET_PARMAS_START(state, payload) {
      state.parmas.start = payload;
    },
    SET_PARMAS_END(state, payload) {
      state.parmas.end = payload;
    },
    SET_PARMAS_CITYNAME(state, payload) {
      state.cityName = payload;
      setCityName(payload);
    },
  },
});
